<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
        <meta content="yes" name="apple-mobile-web-app-capable">
        <meta content="black" name="apple-mobile-web-app-status-bar-style">
        <title>签到拜访</title>
        <script src="__JS__/zepto.min.js"></script>
        <link href="__CSS__/weui.min.css" rel="stylesheet">
        <link rel="stylesheet" href="__SALEMAN__/stylesheets/index.css">
    </head>
    <body>
        <div class="sign_w">
            <header class = "all_header">
                <a class = "h_back h_back_1" href="javascript:history.back(-1);"><img src="__SALEMAN__/images/back_icon.png" alt=""></a>
                <span class = "h_title">签到拜访</span>
                <a class = "h_add" href="javascript:void(0)"></a>
            </header>
            <div class="weui-tab">
                <div class="weui-navbar">
                    <div class="weui-navbar__item weui-bar__item_on">
                        可签到
                    </div>
                    <div class="weui-navbar__item">
                        附近的
                    </div>
                    <div class="weui-navbar__item">
                        已签到
                    </div>
                </div>
                <div class="weui-tab__panel">
                    <div class="sign_list" style = "display: block;">
                        <div class="weui-panel__bd cansign-box">

                        </div>
                    </div>
                    <div class="weui-loadmore" style='none'>
  			<i class="weui-loading"></i>
  			<span class="weui-loadmore__tips">正在定位中,请等待...</span>
			</div>
                    <div class="sign_list nearbysign-box">
                    </div>
                    <div class="sign_list alreadysign-box">
                    </div>
                </div>
            </div>
            
        </div>
         
        <input type="hidden" class="userkey" value="签到#{$myself.uid}" />
        <input type="hidden" class="lng" value="" />
        <input type="hidden" class="lat" value="" />
       	
    <include file="./Application/Home/View/default/Saleman/Public/popup.html"/>
    <script src = "__SaleManager__/js/androidback.js"></script>
    <script>
         var locationTime = setTimeout(checkLocation, 100);
        function checkLocation() {
            var checkKey = $('.userkey').val();
            if (checkKey) {
                window.BSFWebView.showInfoFromJs(checkKey);
                $('.weui-loadmore').css('display','block');
            }
        }
      //获取签到经纬度
      function getLatLng(){
    		var uid=$('.userkey').val();
            $.ajax({  
                url:"/Home/Saleman/Public/getSign",  
                type:"post",  
                async: false,
                cache: false,
               /*  contentType: false, */
               /*  processData: false,  */
               data:{'uid':uid},
              	dataType:"json",
                success: function (returndata) {
                		if(returndata.code==1){
                			$('.lng').val(returndata.data.longitude);
                			$('.lat').val(returndata.data.latitude);
                			$('.weui-loadmore').css('display','none');
					return ;
                			//clearInterval(getAdd);
                		}else{
                			checkLocation();
                			getLatLng();
                		}
                },
                error: function (returndata) {
				return;
                		//getLatLng();
                }
           	 }) 
      }
    //获取经纬度		
   /*      function getLngLat(lng,lat){
        		$('.lng').val(lng);
        		$('.lat').val(lat);
        		alert("经度:"+lng+"，纬度:"+lat);
        }
         */
        var clinicTime = false;
        var itemIndex = 0;
        var autoTime = setTimeout(getClinic, 500);
        $(".weui-navbar__item").on("click", function () {
            var $this = $(this);
            itemIndex = $this.index();
            $(this).addClass('weui-bar__item_on').siblings('.weui-bar__item_on').removeClass('weui-bar__item_on');
            $(".sign_list").hide().eq($(this).index()).show();
            if (itemIndex == '0' || itemIndex == '1') {
                //alert(clinicTime);
                if (!clinicTime) {
                    clinicTime = setInterval(getClinic, 500);
                    $('.weui-loadmore').css('display','block');
                }
            } else {
                getClinic();
                $('.weui-loadmore').css('display','block');
            }
        });


        function getClinic() {
	        	if($('.lat').val().trim().length==0){
	        		getLatLng();
	        	}
            var lat = $('.lat').val();
            var lng = $('.lng').val();
            if (!lat) {
                $('#signiosDialog2').find('.confir_content').html("定位失败");
                $('.weui-loadmore').css('display','none');
                $('#signiosDialog2').show(200);
                return;
            }
            if (!lng) {
                $('#signiosDialog2').find('.confir_content').html("定位失败");
                
                $('.weui-loadmore').css('display','none');
                $('#signiosDialog2').show(200);
                return;
            }
            
            if (itemIndex == '0') {
                $.ajax({
                    url: "/Home/Saleman/Saleman/sign/op/cansign",
                    type: 'post',
                    data: {lng: lng, lat: lat},
                    cache: false,
                    dataType: "json",
                    async: false,
                    success: function (result) {
                        if (autoTime) {
                            clearTimeout(autoTime);
                        }
                        if (clinicTime) {
                            clearInterval(clinicTime);
                        }
                        $('.weui-loadmore').css('display','none');
                        if (result['code'] != 1) {
                            $('#iosDialog2').find('.sure-info').html(result['msg']);
                            $('#iosDialog2').find('.sure-btn').attr('pos_url', '');
                            $('#iosDialog2').show(200);
                            return;
                        }
                        var data = result['data'];
                        var str = '';
                        for (var i = 0; i < data.length; i++) {
                            str += '<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">';
                            str += '<div class="weui-media-box__hd">';
                            if(data[i]['clinic_pic']==''||data[i]['clinic_pic']==undefined){
                            		str += '<img class="weui-media-box__thumb" src="/Public/Home/SaleManager/images/demo.png" alt="">'; 
                            }else{
                       	     	str += '<img class="weui-media-box__thumb" src="' + data[i]['clinic_pic'] + '" alt="">'; 
                            }
                            str += '</div>';
                            str += '<div class="weui-media-box__bd">';
                            str += '<div class="sign_w_name">';
                            str += '<h4 class="weui-media-box__title">' + data[i]['clinic_name'] + '</h4>';
                            str += '<div class="sign_btn signclinic" data-clinic-id='+data[i]["id"]+' ">签到</div>';
                            str += '</div>';
                            str += '<div class="sign_w_num">';
                            str += '<span>预约量：<span>' + data[i]['clinic_treatment_volume'] + '</span></span>';
                            str += '<span>评分：<span>' + data[i]['clinic_score'] + '</span></span>';
                            str += '</div>';
                            str += '<div class="weui-media-box__desc">' + data[i]['clinic_introduction'] + '</div>';
                            str += '</div>';
                            str += '</a>';
                        }
                        $(".cansign-box").html('').append(str);
                    }
                });
            } else if (itemIndex == '1') {
                $.ajax({
                    url: "/Home/Saleman/Saleman/sign/op/nearby",
                    type: 'post',
                    data: {lng: lng, lat: lat},
                    cache: false,
                    dataType: "json",
                    async: false,
                    success: function (result) {
                        if (autoTime) {
                            clearTimeout(autoTime);
                        }
                        if (clinicTime) {
                            clearInterval(clinicTime);
                        }
                        $('.weui-loadmore').css('display','none');
                        if (result['code'] != 1) {
                            $('#iosDialog2').find('.sure-info').html(result['msg']);
                            $('#iosDialog2').find('.sure-btn').attr('pos_url', '');
                            $('#iosDialog2').show(200);
                            return;
                        }
                        var data = result['data'];
                        var str = '';
                        for (var i = 0; i < data.length; i++) {
                            str += '<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">';
                            str += '<div class="weui-media-box__hd">';
                            if(data[i]['clinic_pic']==''||data[i]['clinic_pic']==undefined){
                        			str += '<img class="weui-media-box__thumb" src="/Public/Home/SaleManager/images/demo.png" alt="">'; 
                        		}else{
                   	     		str += '<img class="weui-media-box__thumb" src="' + data[i]['clinic_pic'] + '" alt="">'; 
                        		}
                            //str += '<img class="weui-media-box__thumb" src="' + data[i]['clinic_pic'] + '" alt="">';
                            str += '</div>';
                            str += '<div class="weui-media-box__bd">';
                            str += '<div class="sign_w_name">';
                            str += '<h4 class="weui-media-box__title">' + data[i]['clinic_name'] + '</h4>';
                            str += '<div class="sign_btn">无法签到</div>';
                            str += '</div>';
                            str += '<div class="sign_w_num">';
                            str += '<span>预约量：<span>' + data[i]['clinic_treatment_volume'] + '</span></span>';
                            str += '<span>评分：<span>' + data[i]['clinic_score'] + '</span></span>';
                            str += '</div>';
                            str += '<div class="weui-media-box__desc">' + data[i]['clinic_introduction'] + '</div>';
                            str += '</div>';
                            str += '</a>';
                        }
                        $(".nearbysign-box").html('').append(str);
                    }
                });
            } else if (itemIndex == '2') {
                if (autoTime) {
                    clearTimeout(autoTime);
                }
                if (clinicTime) {
                    clearInterval(clinicTime);
                }
                $.ajax({
                    url: "/Home/Saleman/Saleman/sign/op/alreadysign",
                    type: 'post',
                    cache: false,
                    dataType: "json",
                    success: function (result) {

                        if (result['code'] != 1) {
                            $('#iosDialog2').find('.sure-info').html(result['msg']);
                            $('#iosDialog2').find('.sure-btn').attr('pos_url', '');
                            $('.weui-loadmore').css('display','none');
                            $('#iosDialog2').show(200);
                            return;
                        }
                        $('.weui-loadmore').css('display','none');
                        var data = result['data'];
                        var str = '';
                        for (var i = 0; i < data.length; i++) {

                            str += '<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">';
                            str += '<div class="weui-media-box__hd">';
                            if(data[i]['clinic_pic']==''||data[i]['clinic_pic']==undefined){
                        			str += '<img class="weui-media-box__thumb" src="/Public/Home/SaleManager/images/demo.png" alt="">'; 
	                        }else{
	                   	     	str += '<img class="weui-media-box__thumb" src="' + data[i]['clinic_pic'] + '" alt="">'; 
	                        }
                            //str += '<img class="weui-media-box__thumb" src="' + data[i]['clinic_pic'] + '" alt="">';
                            str += '</div>';
                            str += '<div class="weui-media-box__bd">';
                            str += '<div class="sign_w_name">';
                            str += '<h4 class="weui-media-box__title">' + data[i]['clinic_name'] + '</h4>';
                            str += '<div class="sign_btn alread_sign">已签到</div>';
                            str += '</div>';
                            str += '<div class="sign_w_num">';
                            str += '<span>预约量：<span>' + data[i]['clinic_treatment_volume'] + '</span></span>';
                            str += '<span>评分：<span>' + data[i]['clinic_score'] + '</span></span>';
                            str += '</div>	';
                            str += '<div class="weui-media-box__desc">' + data[i]['clinic_introduction'] + '</div>';
                            str += '</div>';
                            str += '</a>';
                        }
                        $(".alreadysign-box").html('').append(str);

                    }
                });
            }
        }
        
      //签到
     $(document).on('click','.signclinic',function(){
    	 	$.ajax({  
             url:"/Home/Saleman/Saleman/sign/op/sign",  
             type:"post",  
             async: false,
             cache: false,
            	data:{'clinic_id':$(this).attr('data-clinic-id')},
           	dataType:"json",
             success: function (returndata) {
             		if(returndata.code==1){
             			 $('#iosDialogsign').find('.sure-info').html('签到成功');
                        // $('#iosDialogsign').find('.sure-btn').attr('pos_url','/Home/Saleman/Saleman/sign.html');
                         $('#iosDialogsign').show(200);
                         return;
             		}else{
             			 $('#iosDialogsign').find('.sure-info').html(returndata.msg);
                         //$('#iosDialogsign').find('.sure-btn').attr('pos_url', '/Home/Saleman/Saleman/sign.html');
                         $('#iosDialogsign').show(200);
             		}
             },
             error: function (returndata) {
                
             }
        	 })
     })
     $(document).on('click','.signsure-btn',function(){
    	 	location.href='/Home/Saleman/Saleman/sign.html';
     });
     $(document).on('click','.signcancels-btn',function(){
    	 	$('#signiosDialog2').hide(200);
    	 	if (autoTime) {
             clearTimeout(autoTime);
         }
         if (clinicTime) {
             clearInterval(clinicTime);
         }
  });
     
 
    </script>

    <script src = "__SALEMAN__/js/index.js"></script>
</body>
</html>